package com.kgc.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.kgc.api.goods.GoodsItemApi;
import com.kgc.bean.GoodsItem;
import com.kgc.service.AddGoodsStockService;
import com.kgc.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * Created on 2021/6/23.
 * Author: lzy
 * Description: 添加商品业务层
 */
@Service
@Slf4j
public class AddGoodsStockServiceImpl implements AddGoodsStockService {


    @Reference(timeout = 30000)
    private GoodsItemApi goodsItemApi;



    @Override
    public boolean judgeGoodsExists(String goodsId) {
        log.info("--------- 是否存该商品：{}", goodsItemApi.whetherTheProductExists(goodsId));
        return goodsItemApi.whetherTheProductExists(goodsId);
    }

    @Override
    public boolean queryUpdateGoodsStock(String goodsId, Integer goodsStock) {
        GoodsItem goodsItem = goodsItemApi.returnProductInformationAccordingToProductId(goodsId);

        int stock = goodsItem.getGoodsStock();
        log.info(" ------ 当前数据库的商品库存，{}",stock);
        goodsStock = goodsStock + stock;
        return goodsItemApi.updateGoodsStockByGoodsId(goodsId,goodsStock);
    }

}
